package com.example.kingdee.KingdeeCreate.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.example.kingdee.KingdeeCreate.CreateBill;
import com.example.kingdee.KingdeeCreate.dto.CreateInDto;
import com.example.kingdee.common.StringUtils;
import com.example.kingdee.common.constant.YiTiConstant;
import com.example.kingdee.entity.ItemsItem;
import com.example.kingdee.exception.ProcedureException;
import com.example.kingdee.kingdeeBridge.common.RequestResult;
import com.example.kingdee.mapper.TBxStMapper;
import com.example.kingdee.sqlTool.SqlTool;
import com.example.kingdee.sqlTool.common.DataObject;
import com.example.kingdee.sqlTool.sqltoolEnum.FormIdEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 创建销售订单
 */
@Service
public class CreateSalBillImpl implements CreateBill {

    @Autowired
    private SqlTool sqlTool;

    @Autowired
    private TBxStMapper tBxStMapper;

    @Override
    public void preposition(CreateInDto createInDto) {

    }

    public void verifySalBill(CreateInDto createInDto) {
        String userName = createInDto.getUserName();
        Object orgNumber = createInDto.getOrgNumber();//销售组织
        //删除历史校验数据
        tBxStMapper.deleteNgData(userName);
        //查询异常数据
        List<Map<String, Object>> ngdataList = tBxStMapper.getNgdata(userName, orgNumber);
        for (Map<String, Object> ngdata : ngdataList) {
            ngdata.put("userName", userName);
            tBxStMapper.insertNgData(ngdata);
        }
    }

    //创建云星空销售订单
    public RequestResult createKingdeeSal(CreateInDto createInDto){
        Object billType = createInDto.getReserved1();//单据类型
        Object salOrg = createInDto.getReserved2();//销售组织
        Object salMan = createInDto.getReserved3();//销售员
        Object salModel = createInDto.getReserved4();//销售模式
        Object customerNumber = createInDto.getReserved5();//客户
        Object logisticsCompany = createInDto.getReserved6();//快递公司
        Object lId = createInDto.getReserved7();//快递单号
        Object oId = createInDto.getReserved8();//聚水潭内部订单号
        Object orderDate = createInDto.getReserved9();//订单日期
        Object sendDate = createInDto.getReserved10();//发货日期
        Object saiModel = createInDto.getReserved11();//发货日期
        Object supNumberParam = createInDto.getReserved12();//承运商

        //单据类型 FBillTypeID, 002-电商销售订单， XSDD01_SYS-标准销售订单，
        Map<String, Object> fBillTypeID = new HashMap<>();
        fBillTypeID.put("FNUMBER", billType);
        //承运商
        Map<String, Object> supNumber = new HashMap<>();
        supNumber.put("FNUMBER", supNumberParam);
        //销售组织 FSaleOrgId
        Map<String, Object> saleOrgId = new HashMap<>();
        saleOrgId.put("FNumber", salOrg);
        //库存组织 FSaleOrgId
        Map<String, Object> stockOrgId = new HashMap<>();
        stockOrgId.put("FNumber", "001");
        //客户编码
        Map<String, Object> customerId = new HashMap<>();
        customerId.put("FNumber",customerNumber);
        //交货方式 JHFS01_SYS(发货) JHFS02_SYS(自提) FHeadDeliveryWay 非必填
        Map<String, Object> headDeliveryWay = new HashMap<>();
        headDeliveryWay.put("FNumber", "JHFS01_SYS");
        //销售员 FSalerId
        Map<String, Object> salId = new HashMap<>();
        salId.put("FNumber", salMan);
        //财务信息  FSaleOrderFinance
        Map<String,Object> saleOrderFinance = new LinkedHashMap<>();
        //结算币别  FSettleCurrId
        Map<String, Object> settleCurrId = new HashMap<>();
        settleCurrId.put("FNumber", "PRE001");
        saleOrderFinance.put("FSettleCurrId", settleCurrId);
        saleOrderFinance.put("FExchangeRate", 1);

        List<Map<String, Object>> entryList = createInDto.getEntryList();
        //订单明细  FSaleOrderEntry
        List<Map<String, Object>> saleOrderInfoList = new ArrayList<>();
        for (Map<String, Object> item : entryList) {
            //查询计量单位
            String unitNumber = tBxStMapper.getUnitNumber(item.get("itemNumber").toString());
            Map<String, Object> materialId = new HashMap<>(); //物料编码 必填
            materialId.put("FNumber", item.get("itemNumber"));
            Map<String, Object> materialUnit = new HashMap<>(); //销售单位 必填
            materialUnit.put("FNumber", unitNumber);
            //交货安排
            List<Map<String, Object>> orderEntryPlanList = new ArrayList<>();
            Map<String,Object> orderEntryPlan = new LinkedHashMap<>();
//            orderEntryPlan.put("FPlanDate", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now().plusDays(1)));
            orderEntryPlan.put("FPlanDate", sendDate);
            orderEntryPlan.put("FPlanQty", item.get("qty"));
            orderEntryPlanList.add(orderEntryPlan);

            String salMaterialAmount = String.valueOf(item.get("qty"));
            BigDecimal bigDecimal = new BigDecimal(salMaterialAmount);
            //构建物料明细
            Map<String,Object> saleOrderEntry = new LinkedHashMap<>();
            saleOrderEntry.put("FMaterialId", materialId);//物料编码 必填
            saleOrderEntry.put("FUnitID", materialUnit);//销售单位 必填
            saleOrderEntry.put("FQty", item.get("qty"));//销售数量 (必填项)
            saleOrderEntry.put("FDeliveryMaxQty", NumberUtil.mul(bigDecimal, 10));//发货上限
            saleOrderEntry.put("FPriceUnitId", materialUnit);//计价单位 必填
            saleOrderEntry.put("FTaxPrice", item.get("price"));//含税单价 (必填项)
            //默认仓库
            if(!StringUtils.isEmpty(String.valueOf(item.get("stockNumber")))){
                HashMap<String, Object> stockId = new HashMap<>();
                stockId.put("fnumber", item.get("stockNumber"));
                saleOrderEntry.put("FSOSTOCKID", stockId);
            }
            //计划跟踪号
            if(!StringUtils.isEmpty(String.valueOf(item.get("planFlotNumber")))){
                saleOrderEntry.put("FMtoNo", item.get("planFlotNumber"));
            }
            saleOrderEntry.put("FIsFree", false);//是否赠品
            saleOrderEntry.put("FEntryTaxRate", 0);//税率%
//            saleOrderEntry.put("FDeliveryDate", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now().plusDays(1)));//要货日期
            saleOrderEntry.put("FDeliveryDate", sendDate);//要货日期
            if (item.get("commissionSale").toString().equals("1")){
                //是否委托销售
                saleOrderEntry.put("FStockOrgId", stockOrgId);//库存组织 必填
                saleOrderEntry.put("FOwnerId", saleOrgId);//货主 必填
            }
            saleOrderEntry.put("FSettleOrgIds", saleOrgId);//结算组织 必填
            saleOrderEntry.put("FReserveType", "1");//预留类型 (必填项)
            saleOrderEntry.put("FStockUnitID", materialUnit);//库存单位 (必填项)
            saleOrderEntry.put("FOUTLMTUNIT", "SAL");//超发控制单位类型 (必填项)
            saleOrderEntry.put("FOrderEntryPlan", orderEntryPlanList);//交货安排
            saleOrderEntry.put("fnote", "系统自动同步");//备注
            saleOrderInfoList.add(saleOrderEntry);
        }
        //添加销售订单
        DataObject saleOrder = new DataObject(FormIdEnum.salSaleOrder);
        //创建日期
//        saleOrder.setAttribute("FBillNo", createInDto.getReserved1());//单据编号 必填
        saleOrder.setAttribute("FBillTypeID", fBillTypeID);//单据类型 必填 固定值
//        saleOrder.setAttribute("FDate", SqlTool.getNowForString());//日期 (必填项)
        saleOrder.setAttribute("FDate", orderDate);//日期 (必填项)
        saleOrder.setAttribute("FSaleOrgId", saleOrgId);//销售组织 (必填项)
        saleOrder.setAttribute("FCustId", customerId);//客户 (必填项)
        saleOrder.setAttribute("FHeadDeliveryWay", headDeliveryWay);//交货方式
        saleOrder.setAttribute("FSalerId", salId);//销售员  (必填项)
        saleOrder.setAttribute("FNote", logisticsCompany + " " + lId);//备注
        saleOrder.setAttribute("F_USAW_Combo", salModel);//销售模式
        saleOrder.setAttribute("FCarrierID", supNumber);//承运商
        saleOrder.setAttribute("F_WMVJ_Text_qtr", oId);//内部订单号
        saleOrder.setAttribute("FSaleOrderFinance", saleOrderFinance);//财务信息
        saleOrder.setAttribute("FSaleOrderEntry", saleOrderInfoList);//订单明细
        if (!String.valueOf(saiModel).equals("XXQD")){
            //销售模式不为线下订单的进行自动审核
            saleOrder.setIsAutoSubmitAndAudit(true);
        }

        try {
            Map<String, Object> result = sqlTool.editForDataObject(saleOrder);
            if (result.get("code").toString().equals("200")){
                return RequestResult.ofSuccess(result);
            }else {
                return RequestResult.ofError(result.get("msg").toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ProcedureException("无法调用云星空接口");
        }

    }

    //创建云星空销售订单
    public void editCreateInDto(CreateInDto createInDto){
        String userName = createInDto.getUserName();
        Object billType = createInDto.getReserved1();//单据类型
        Object salOrg = createInDto.getReserved2();//销售组织
        Object salMan = createInDto.getReserved3();//销售员
        Object salModel = createInDto.getReserved4();//销售模式
        Object salEsp = createInDto.getReserved5();//承运商
        Object stockNumber = createInDto.getReserved6();//仓库
        //判断是否有异常数据
        tBxStMapper.deleteNgData(userName);
        tBxStMapper.deleteNgResult(userName);
        //查询异常数据
        List<Map<String, Object>> ngdataList = tBxStMapper.getNgdata(userName, salOrg);
        if (ngdataList != null && ngdataList.size() > 0){
            throw new ProcedureException("当前数据有异常，请先进行数据校验");
        }
        List<Map<String, Object>> entryList = createInDto.getEntryList();
        for (int i = 0; i < entryList.size(); i++) {
            Map<String, Object> entry = entryList.get(i);
            Map<String, Object> syncResult = new HashMap<>();
            syncResult.put("fseq", i+1);
            syncResult.put("ioId", entry.get("ioId"));
            syncResult.put("createUser", userName);
            //判断内部订单号是否已经通同步过
            int count = tBxStMapper.isSync(entry.get("ioId"));
            if (count > 0){
                syncResult.put("ngMsg", "该内部订单号已经同步过");
                syncResult.put("syncResult", "同步失败");
                tBxStMapper.insertSyncSal(syncResult);
                continue;
            }
            //单据类型 FBillTypeID, 002-电商销售订单， XSDD01_SYS-标准销售订单，
            Map<String, Object> fBillTypeID = new HashMap<>();
            fBillTypeID.put("FNUMBER", billType);
            //承运商
            Map<String, Object> FCarrierID = new HashMap<>();
            FCarrierID.put("FNUMBER", salEsp);
            //销售组织 FSaleOrgId
            Map<String, Object> saleOrgId = new HashMap<>();
            saleOrgId.put("FNumber", salOrg);
            Map<String, Object> customerId = new HashMap<>();
            customerId.put("FNumber", entry.get("cusNumber"));
            //交货方式 JHFS01_SYS(发货) JHFS02_SYS(自提) FHeadDeliveryWay 非必填
            Map<String, Object> headDeliveryWay = new HashMap<>();
            headDeliveryWay.put("FNumber", "JHFS02_SYS");
            //销售员 FSalerId
            Map<String, Object> salId = new HashMap<>();
            salId.put("FNumber", salMan);
            //财务信息  FSaleOrderFinance
            Map<String,Object> saleOrderFinance = new LinkedHashMap<>();
            //结算币别  FSettleCurrId
            Map<String, Object> settleCurrId = new HashMap<>();
            settleCurrId.put("FNumber", "PRE001");
            saleOrderFinance.put("FSettleCurrId", settleCurrId);
            saleOrderFinance.put("FExchangeRate", 1);

            //订单明细  FSaleOrderEntry
            List<Map<String, Object>> saleOrderInfoList = new ArrayList<>();
            Map<String,Object> saleOrderEntry = new LinkedHashMap<>();
            String unitNumber = tBxStMapper.getUnitNumber(entry.get("itemNumber").toString());
            Map<String, Object> materialId = new HashMap<>(); //物料编码 必填
            materialId.put("FNumber", entry.get("itemNumber"));
            Map<String, Object> FSOStockId = new HashMap<>(); //仓库 必填
            FSOStockId.put("FNumber", stockNumber);
            Map<String, Object> materialUnit = new HashMap<>(); //销售单位 必填
            materialUnit.put("FNumber", unitNumber);
            Map<String, Object> priceUnitId = new HashMap<>(); //计价单位 必填
            priceUnitId.put("FNumber", unitNumber);
            Map<String, Object> settleOrgIds = new HashMap<>(); //结算组织 必填
            settleOrgIds.put("FNumber", salOrg);
            Map<String, Object> stockUnitID = new HashMap<>(); //库存单位 (必填项)
            stockUnitID.put("FNumber", unitNumber);
            //交货安排
            List<Map<String, Object>> orderEntryPlanList = new ArrayList<>();
            Map<String,Object> orderEntryPlan = new LinkedHashMap<>();
            orderEntryPlan.put("FPlanDate", SqlTool.getNowForString());
            orderEntryPlan.put("FPlanQty", entry.get("qty"));
            orderEntryPlanList.add(orderEntryPlan);

            String salMaterialAmount = String.valueOf(entry.get("qty"));
            BigDecimal bigDecimal = new BigDecimal(salMaterialAmount);
            saleOrderEntry.put("FMaterialId", materialId);//物料编码 必填
            saleOrderEntry.put("FUnitID", materialUnit);//销售单位 必填
            saleOrderEntry.put("FQty", entry.get("qty"));//销售数量 (必填项)
            saleOrderEntry.put("FDeliveryMaxQty", NumberUtil.mul(bigDecimal, 10));//发货上限
            saleOrderEntry.put("FPriceUnitId", priceUnitId);//计价单位 必填
            saleOrderEntry.put("FTaxPrice", entry.get("price"));//含税单价 (必填项)
            saleOrderEntry.put("FIsFree", false);//是否赠品
            saleOrderEntry.put("FEntryTaxRate", 0);//税率%
            saleOrderEntry.put("FDeliveryDate", entry.get("orderDate"));//要货日期
            saleOrderEntry.put("FSettleOrgIds", settleOrgIds);//结算组织 必填
            saleOrderEntry.put("FReserveType", "1");//预留类型 (必填项)
            saleOrderEntry.put("FStockUnitID", stockUnitID);//库存单位 (必填项)
            saleOrderEntry.put("FOUTLMTUNIT", "SAL");//超发控制单位类型 (必填项)
            saleOrderEntry.put("FOrderEntryPlan", orderEntryPlanList);//交货安排
            saleOrderEntry.put("FSOStockId", FSOStockId);//仓库
            saleOrderEntry.put("fnote", entry.get("ioId"));//备注
            saleOrderInfoList.add(saleOrderEntry);

            //添加销售订单
            DataObject saleOrder = new DataObject(FormIdEnum.salSaleOrder);
            //创建日期
//            saleOrder.setAttribute("FBillNo", createInDto.getReserved1());//单据编号 必填
            saleOrder.setAttribute("FBillTypeID", fBillTypeID);//单据类型 必填 固定值
            saleOrder.setAttribute("FDate", entry.get("orderDate"));//日期 (必填项)
            saleOrder.setAttribute("FSaleOrgId", saleOrgId);//销售组织 (必填项)
            saleOrder.setAttribute("FCustId", customerId);//客户 (必填项)
            saleOrder.setAttribute("FHeadDeliveryWay", headDeliveryWay);//交货方式
            saleOrder.setAttribute("FSalerId", salId);//销售员  (必填项)
            saleOrder.setAttribute("FNote", entry.get("esp") + " " + entry.get("espBill"));//备注
            saleOrder.setAttribute("F_USAW_Combo", salModel);//销售模式
            saleOrder.setAttribute("FCarrierID", FCarrierID);//承运商
            saleOrder.setAttribute("FSaleOrderFinance", saleOrderFinance);//财务信息
            saleOrder.setAttribute("FSaleOrderEntry", saleOrderInfoList);//订单明细
//            saleOrder.setIsAutoSubmitAndAudit(true);

            try {
                Map<String, Object> result = sqlTool.editForDataObject(saleOrder);
                if (!result.get("code").toString().equals("200")){
                    syncResult.put("ngMsg", result.get("msg"));
                    syncResult.put("syncResult", "同步失败");
                    tBxStMapper.insertSyncSal(syncResult);
                }else {
                    syncResult.put("ngMsg", "无");
                    syncResult.put("kingdeeNumber", result.get("number"));
                    syncResult.put("syncResult", "同步成功");
                    tBxStMapper.insertSyncSal(syncResult);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new ProcedureException("无法调用云星空接口");
            }
        }
    }

    /*
     *
     * @param createInDto
     * reserved1为调入仓库编码，reserved2为调入仓位编码
     * @return
     */
    @Override
    public RequestResult createSrcBill(CreateInDto createInDto) {
        Object orgName = createInDto.getReserved7();//组织名称
        //查询组织编码
        String orgNumber = tBxStMapper.getOrgNumber(orgName);
        if (StringUtils.isEmpty(orgNumber)){
            return RequestResult.ofError("采购单供应商字段错误，请选择正确的组织");
        }
        //单据类型 FBillTypeID, 002-电商销售订单， XSDD01_SYS-标准销售订单，
        Map<String, Object> fBillTypeID = new HashMap<>();
        fBillTypeID.put("FNUMBER", "XSDD01_SYS");
        //设定要货日期为当前日期加15天
        Date date = new Date();
        DateTime newDate = DateUtil.offsetDay(date, 10);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String deliveryDate = format.format(newDate);
        //销售组织 FSaleOrgId
        Map<String, Object> saleOrgId = new HashMap<>();
        saleOrgId.put("FNumber", orgNumber);
        //客户 FCustId
        Map<String, Object> customerId = new HashMap<>();
        customerId.put("FNumber", YiTiConstant.SAL_CUSTOMER_NUMBER);
        //交货方式 JHFS01_SYS(发货) JHFS02_SYS(自提) FHeadDeliveryWay 非必填
        Map<String, Object> headDeliveryWay = new HashMap<>();
        headDeliveryWay.put("FNumber", "JHFS02_SYS");
        //销售员 FSalerId
        Map<String, Object> salId = new HashMap<>();
        salId.put("FNumber", YiTiConstant.SAL_MAN_NUMBER);
        //财务信息  FSaleOrderFinance
        Map<String,Object> saleOrderFinance = new LinkedHashMap<>();
        //结算币别  FSettleCurrId
        Map<String, Object> settleCurrId = new HashMap<>();
        settleCurrId.put("FNumber", "PRE001");
        saleOrderFinance.put("FSettleCurrId", settleCurrId);
        saleOrderFinance.put("FExchangeRate", 1);
        //订单明细  FSaleOrderEntry
        List<Map<String, Object>> saleOrderInfoList = new ArrayList<>();
        List<ItemsItem> items = createInDto.getItems();
        for (ItemsItem item : items) {
            Map<String,Object> saleOrderEntry = new LinkedHashMap<>();
            Integer row = tBxStMapper.itemIsExist(item.getSkuId(), orgNumber);
            if (row == 0){
                saleOrderEntry.put("F_WMVJ_TEXT_TZK", item.getSkuId());//聚水潭物料编码
                item.setSkuId("9999");
            }
            String unitNumber = tBxStMapper.getUnitNumber(item.getSkuId());
            Map<String, Object> materialId = new HashMap<>(); //物料编码 必填
            materialId.put("FNumber", item.getSkuId());
            Map<String, Object> materialUnit = new HashMap<>(); //销售单位 必填
            materialUnit.put("FNumber", unitNumber);
            Map<String, Object> priceUnitId = new HashMap<>(); //计价单位 必填
            priceUnitId.put("FNumber", unitNumber);
            Map<String, Object> settleOrgIds = new HashMap<>(); //结算组织 必填
            settleOrgIds.put("FNumber", YiTiConstant.SAL_ORG_NUMBER);
            Map<String, Object> stockUnitID = new HashMap<>(); //库存单位 (必填项)
            stockUnitID.put("FNumber", unitNumber);

            //交货安排
            List<Map<String, Object>> orderEntryPlanList = new ArrayList<>();
            Map<String,Object> orderEntryPlan = new LinkedHashMap<>();
            orderEntryPlan.put("FPlanDate", deliveryDate);
            orderEntryPlan.put("FPlanQty", item.getQty());
            orderEntryPlanList.add(orderEntryPlan);

            String salMaterialAmount = String.valueOf(item.getQty());
            BigDecimal bigDecimal = new BigDecimal(salMaterialAmount);
            saleOrderEntry.put("FMaterialId", materialId);//物料编码 必填
            saleOrderEntry.put("FUnitID", materialUnit);//销售单位 必填
            saleOrderEntry.put("FQty", item.getQty());//销售数量 (必填项)
            saleOrderEntry.put("FDeliveryMaxQty", NumberUtil.mul(bigDecimal, 10));//发货上限
            saleOrderEntry.put("FPriceUnitId", priceUnitId);//计价单位 必填
            saleOrderEntry.put("FTaxPrice", item.getPrice());//含税单价 (必填项)
            saleOrderEntry.put("FIsFree", false);//是否赠品
            saleOrderEntry.put("FEntryTaxRate", item.getTaxRate());//税率%
            saleOrderEntry.put("FDeliveryDate", deliveryDate);//要货日期
            saleOrderEntry.put("FSettleOrgIds", settleOrgIds);//结算组织 必填
            saleOrderEntry.put("FEntryNote", item.getRemark());//备注 必填
            saleOrderEntry.put("FReserveType", "1");//预留类型 (必填项)
            saleOrderEntry.put("FStockUnitID", stockUnitID);//库存单位 (必填项)
            saleOrderEntry.put("FOUTLMTUNIT", "SAL");//超发控制单位类型 (必填项)
            saleOrderEntry.put("FOrderEntryPlan", orderEntryPlanList);//交货安排

            if (item.getQty() != 0.0){
                saleOrderInfoList.add(saleOrderEntry);
            }
        }
        //添加销售订单
        DataObject saleOrder = new DataObject(FormIdEnum.salSaleOrder);
        //创建日期
        saleOrder.setAttribute("FBillNo", createInDto.getReserved1());//单据编号 必填
        saleOrder.setAttribute("FBillTypeID", fBillTypeID);//单据类型 必填 固定值
        saleOrder.setAttribute("FDate", createInDto.getReserved2());//日期 (必填项)
        saleOrder.setAttribute("FSaleOrgId", saleOrgId);//销售组织 (必填项)
        saleOrder.setAttribute("FCustId", customerId);//客户 (必填项)
        saleOrder.setAttribute("FHeadDeliveryWay", headDeliveryWay);//交货方式
        saleOrder.setAttribute("FSalerId", salId);//销售员  (必填项)
        saleOrder.setAttribute("FNote", createInDto.getReserved3());//备注
        saleOrder.setAttribute("F_WMVJ_TEXT_QTR", createInDto.getReserved4());//聚水潭采购单号
        saleOrder.setAttribute("F_WMVJ_DATE_RE5", createInDto.getReserved5());//聚水潭审核日期
        saleOrder.setAttribute("F_WMVJ_TEXT_APV", createInDto.getReserved6());//聚水潭入库仓库
        saleOrder.setAttribute("FSaleOrderFinance", saleOrderFinance);//财务信息
        saleOrder.setAttribute("FSaleOrderEntry", saleOrderInfoList);//订单明细

        try {
            Map<String, Object> result = sqlTool.editForDataObject(saleOrder);
            if (result.get("code").toString().equals("200")){
                return RequestResult.ofSuccess(result);
            }else {
                return RequestResult.ofError(result.get("msg").toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ProcedureException("无法调用云星空接口");
        }
    }

    //创建云星空销售订单
    public void closeKingdeeSal(CreateInDto createInDto){
        try {
            //将销售订单关闭
            sqlTool.excuteStartWork(createInDto.getReserved1().toString(), FormIdEnum.salSaleOrder, "YLBillClose");
        }catch (Exception e){
            throw new ProcedureException("生产订单行执行至开工失败");
        }

    }

    @Override
    public void auditTargetBill(String billNo) {
        //提交审核
        sqlTool.auditBill(billNo, FormIdEnum.salSaleOrder);
    }

    @Override
    public void postPosition(RequestResult srcBill, CreateInDto createInDto) {

    }

    @Override
    public void deleteTargetBill(String fid) {
        sqlTool.deleteBill(fid, FormIdEnum.salSaleOrder);
    }




}
